/*
 * @lc app=leetcode.cn id=830 lang=typescript
 *
 * [830] 较大分组的位置
 */

// @lc code=start
function largeGroupPositions(s: string): number[][] {
    let count = 0;
    let last = "";
    let final: number[][] = [];
    for (let i = 0; i < s.length; i++) {
        const element = s[i];
        if (element === last) {
            count++;
        } else {
            if (count >= 3) final.push([i - count, i - 1]);

            last = element;
            count = 1;
        }
    }
    // TODO 记住需要最后一个守护
    if (count >= 3) final.push([s.length - count, s.length - 1]);
    return final;
}

// @lc code=end
